package juc;

import java.util.Collection;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;

public class CallableDemo {
	public static void main(String args[]) throws ExecutionException, InterruptedException {
		MyCallable callable = new MyCallable();
		FutureTask<Integer> futureTask = new FutureTask<>(callable);
		FutureTask<Integer> futureTask1 = new FutureTask<>(callable);
		Thread thread = new Thread(futureTask, "A");
		Thread thread1 = new Thread(futureTask1, "A");
		thread.start();
		thread1.start();
		System.out.println(Thread.currentThread().getName());
		System.out.println(futureTask.get());
	}
}

class MyCallable implements Callable<Integer> {

	@Override
	public Integer call() throws Exception {
		System.out.println(Thread.currentThread().getName());
		System.out.println("===============");
		TimeUnit.SECONDS.sleep(5);
		return 1;
	}
}
